package Affichage;

/**
 * *********************************************************************
 * Module: Description.java Author: Loick Purpose: Defines the Class Description
 * *********************************************************************
 */
import Metier.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Description extends JFrame {

    public java.util.Collection<Descriptable> descriptable;
    public java.util.Collection<Dialogue> dialogue;
    private JButton Modifier = null;
    private final JTextField Libelle;
    private final JTextArea Lien;
    private final JTextArea Description;
    private final JLabel lbl_Description;
    private final JLabel lbl_Libelle;
    private final JLabel lbl_Lien;
    private final JScrollPane Panel_Description;
    private final JScrollPane Panel_LienHypertexte;
    private final CustomPanel Panel_Image;
    private News news;
    private Dialogue dialog;

    public Description() throws IOException {
        lbl_Description = new javax.swing.JLabel();
        lbl_Libelle = new javax.swing.JLabel();
        Libelle = new javax.swing.JTextField();
        Panel_LienHypertexte = new javax.swing.JScrollPane();
        Lien = new javax.swing.JTextArea();
        lbl_Lien = new javax.swing.JLabel();
        Panel_Description = new javax.swing.JScrollPane();
        Description = new javax.swing.JTextArea();
        Panel_Image = new CustomPanel("carte-londres.jpg");
        Modifier = new JButton();
        news = new News();
        dialog = new Dialogue();
    }

    public java.util.Collection<Descriptable> getDescriptable() {
        if (descriptable == null) {
            descriptable = new java.util.HashSet<Descriptable>();
        }
        return descriptable;
    }

    public java.util.Iterator getIteratorDescriptable() {
        if (descriptable == null) {
            descriptable = new java.util.HashSet<Descriptable>();
        }
        return descriptable.iterator();
    }

    public void setDescriptable(java.util.Collection<Descriptable> newDescriptable) {
        removeAllDescriptable();
        for (java.util.Iterator iter = newDescriptable.iterator(); iter.hasNext();) {
            addDescriptable((Descriptable) iter.next());
        }
    }

    public void addDescriptable(Descriptable newDescriptable) {
        if (newDescriptable == null) {
            return;
        }
        if (this.descriptable == null) {
            this.descriptable = new java.util.HashSet<Descriptable>();
        }
        if (!this.descriptable.contains(newDescriptable)) {
            this.descriptable.add(newDescriptable);
        }
    }

    public void removeDescriptable(Descriptable oldDescriptable) {
        if (oldDescriptable == null) {
            return;
        }
        if (this.descriptable != null) {
            if (this.descriptable.contains(oldDescriptable)) {
                this.descriptable.remove(oldDescriptable);
            }
        }
    }

    public void removeAllDescriptable() {
        if (descriptable != null) {
            descriptable.clear();
        }
    }

    public void Afficher_Description(final POI poi) {
        lbl_Description.setText("Description");

        lbl_Libelle.setText("Libellé");
        Libelle.setText(poi.getLibelle());
        Description.setText(poi.getTexte());
        String a = "";
        for (String lien : poi.getHypertexte()) {
            a += lien + "\n";
        }
        Libelle.setEnabled(false);
        Description.setEnabled(false);
        Lien.setEnabled(false);
        Lien.setText(a);
        Lien.setColumns(20);
        Lien.setRows(5);
        Panel_LienHypertexte.setViewportView(Lien);

        lbl_Lien.setText("Lien Hypertexte");

        Description.setColumns(20);
        Description.setLineWrap(true);
        Description.setRows(5);
        Panel_Description.setViewportView(Description);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(Panel_Image);
        Panel_Image.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
        );
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                        .addContainerGap()
                                                        .addComponent(lbl_Lien)
                                                        .addGap(18, 18, 18))
                                                .addGroup(layout.createSequentialGroup()
                                                        .addGap(20, 20, 20)
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(lbl_Libelle)
                                                                .addComponent(lbl_Description))
                                                        .addGap(42, 42, 42)))
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(Libelle)
                                                .addComponent(Panel_Description, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                                                .addComponent(Panel_LienHypertexte))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(Panel_Image, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        )))));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(Libelle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(lbl_Libelle))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(lbl_Description)
                                                .addComponent(Panel_Description, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(Panel_LienHypertexte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(lbl_Lien)))
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(Panel_Image, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(72, 72, 72))
                        )));

        this.setSize(600, 400);
        this.setVisible(true);
    }
}
